package com.devfest.wishmaster.gui;

import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.DatePicker;
import android.widget.EditText;

import com.devfest.wishmaster.R;
import com.devfest.wishmaster.model.WishList;


public class CreateWishListActivity extends Activity {

	private EditText name;
	private DatePicker eventDate;
	private WishList wishlist;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_wishlist);
		setTitle("New Wishlist");
		name = (EditText) findViewById(R.id.name);
		eventDate = (DatePicker) findViewById(R.id.eventDate);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.save_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
			switch (item.getItemId()) {
			case R.id.save:
				saveWishList();
				finish();
				break;
			}
		return super.onOptionsItemSelected(item);
	}

	private void saveWishList() {
		wishlist = new WishList();
		wishlist.setDateCreated(new Date());
		wishlist.setEventDate(getDateFromPicker());
		wishlist.setName(name.getText().toString());
//		wishlist.setUser(user)
//		wishlist.setId(id)
		MyApplication.getInstance().wishLists.add(wishlist);
		finish();
	}
	
	@SuppressWarnings("deprecation")
	private Date getDateFromPicker() {
		int year = eventDate.getYear();
		int month = eventDate.getMonth();
		int day = eventDate.getDayOfMonth();
		return new Date(year, month, day);
	}
}
